﻿@*
    TicketDesk - Attribution notice
    Contributor(s):

         Stephen Redd (stephen@reddnet.net, http://www.reddnet.net)

    This file is distributed under the terms of the Microsoft Public
    License (Ms-PL). See http://opensource.org/licenses/MS-PL
    for the complete terms of use.

    For any distribution that contains code from this file, this notice of
    attribution must remain intact, and a copy of the license must be
    provided to the recipient.
*@
@using System.Text.RegularExpressions
@using TicketDesk.Domain
@using TicketDesk.Domain.Model
@model IEnumerable<Ticket>
@section title{
    Ticket Search
}
@section scripts
{
    @Scripts.Render("~/bundles/search");
    <script type="text/javascript">
        $(document).ready(function () {
            window.search.activate(null);
        });
    </script>
}
<main>
    <div class="container">
        <fieldset>
            <legend class="col-lg-8 col-lg-offset-2 col-md-9 col-md-offset-1 col-sm-12">
                Search
            </legend>
            <div class="col-lg-7 col-lg-offset-3 col-md-8 col-md-offset-2 col-sm-12">
                @if (ViewBag.IsMultiProject ?? false)
                {
                    <div class="alert alert-info ">@ViewBag.SearchProjectName</div>
                }
                @foreach (var item in Model)
                {
                    <div id="ticketDetailPanel" class="panel panel-info clickable">
                        <div class="panel-heading" style="padding: 3px 5px;">
                            <div class="row ">
                                <div class="row-same-height row-full-height">
                                    <div class="col-xs-2 col-sm-2 col-xs-height col-full-height text-center panel-title" style="border-right: 1px solid #dcdcdc;">
                                        @item.TicketStatus.GetDescription()
                                    </div>
                                    <div class="col-xs-2 col-sm-1 col-xs-height col-full-height text-center panel-title" style="border-right: 1px solid #dcdcdc;">
                                        #@item.TicketId
                                    </div>
                                    <div class="col-xs-8 col-sm-9 col-xs-height col-full-height panel-title">
                                        <a href="@Url.Action("Index", "Ticket", new {id = item.TicketId})">
                                            @item.Title
                                        </a>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="panel-body" style="padding-top: 0; padding-bottom: 0;">
                            <div class="row row-no-padding row-same-height row-full-height">
                                <div class="col-sm-12 col-xs-height col-full-height ">
                                    <div class="" style="border-bottom: 1px solid #B3CBDF; padding: 3px; background-color: #F7F7F7;">
                                        <div class="pull-right">
                                            @if (ViewBag.IsMultiProject ?? false)
                                            {
                                                <div class="text-primary">
                                                    <i class="fa fa-book"></i>
                                                    @item.Project.ProjectName
                                                </div>
                                            }
                                            @if (!string.IsNullOrEmpty(item.TagList))
                                            {
                                                <div class="text-muted text-default">

                                                    @foreach (var tag in item.TagList.Split(','))
                                                    {
                                                        <div><i class="fa fa-tag"></i> @tag</div>
                                                    }
                                                </div>
                                            }


                                        </div>
                                        
                                        <div>
                                            <div>@item.Priority Priority @item.Category @item.TicketType</div>
                                            <div>
                                                Assigned To:
                                                @if (string.IsNullOrEmpty(item.AssignedTo))
                                                {
                                                    <span class='label label-warning'>Unassigned</span>
                                                }
                                                else
                                                {
                                                    @item.GetAssignedToInfo().DisplayName
                                                }
                                            </div>
                                            <div>
                                                Owned By:
                                                @item.GetOwnerInfo().DisplayName
                                            </div>
                                            <div class="hidden-sm">
                                                Updated by @item.GetLastUpdatedByInfo().DisplayName at @item.LastUpdateDate.DateTime.ToShortDateString() @item.LastUpdateDate.DateTime.ToShortTimeString()
                                            </div>
                                        </div>
                                    </div>
                                    <div class="" style="margin: 0; padding: 0;">
                                        <div class="" id="detailsText" style="padding: 5px;">
                                            @{
                                                var details = Regex.Replace(item.HtmlDetails().ToString(), @"<(.|\n)*?>", "");
                                                if (details.Length > 100)
                                                {
                                                    details = new string(details.Take(100).ToArray()) + "\n\n...";
                                                }
                                            }
                                            @details
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                                                }
            </div>
        </fieldset>

    </div>
</main>
